package jdbc.mysql.gzpowernode;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;

public class test01 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try {
            //1.
            String driver = "com.mysql.jdbc.Driver";

            Class.forName(driver);

            //Driver driver = new com.mysql.jdbc.Driver();
            //DriverManager.registerDriver(driver);
            //2.
            // url = "jdbc:mysql://ip:port/databaseName
            //localIp:127.0.0.1
            String url = "jdbc:mysql://127.0.0.1:3306/gzpowernode?&useSSL=false";
            String user = "root";
            String password = "123456";
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("DatabaceObject = " + conn);
            //3.gain databaseObject(be used to catch out SQL program)
            stmt = conn.createStatement();
            //4.catch SQL program
            String sql = "insert into t_student(name,id,classno) values('yy',7,101)";
            int count = stmt.executeUpdate(sql);
            System.out.println(count == 1 ? "yes" : "no");
        } catch (Exception e) {
            e.printStackTrace();
            //5.deal selection result
        } finally {
            //6.release resources
            try {
                if (stmt != null) {
                    stmt.close();
                }

            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {

                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }


        }


    }
}